package Icr.RegisteredAssistant;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TableRow;
import android.widget.TextView;

public class CompanyFindActivity extends Activity {

	Spinner spinner;
	EditText editText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.companyfind);

		spinner = (Spinner) findViewById(R.id.spinner1);
		editText = (EditText) findViewById(R.id.editText1);

		((Spinner) findViewById(R.id.spinner1))
				.setOnItemSelectedListener(new MyOnItemSelectedListener());

		((Button) findViewById(R.id.Find))
				.setOnClickListener(new OnClickListener() {

					public void onClick(View v) {
						// TODO Auto-generated method stub

						if (spinner.getSelectedItemPosition() == 0) {

							ComponentName component = new ComponentName(
									CompanyFindActivity.this,
									CompanyActivity.class);
							Intent intent = new Intent();

							intent.putExtra("value", editText.getText()
									.toString());

							intent.setComponent(component);
							startActivity(intent);
						} else {
							ComponentName component = new ComponentName(
									CompanyFindActivity.this,
									CompanyListActivity.class);
							Intent intent = new Intent();

							intent.putExtra("value", editText.getText()
									.toString());

							if (spinner.getSelectedItemPosition() == 1) {
								intent.putExtra("language", "en");
							} else {
								intent.putExtra("language", "ch");
							}

							intent.setComponent(component);
							startActivity(intent);
						}

					}
				});

	}

	public class MyOnItemSelectedListener implements OnItemSelectedListener {

		public void onItemSelected(AdapterView<?> parent, View view, int pos,
				long id) {
			if (pos == 0) {
				TextView textView = (TextView) findViewById(R.id.textView1);
				textView.setText(getString(R.string.CompanyNo));
			} else {
				TextView textView = (TextView) findViewById(R.id.textView1);
				textView.setText(getString(R.string.CompanyName));
			}
		}

		public void onNothingSelected(AdapterView parent) {
			// Do nothing.
		}
	}

}
